package com.last1mile.validator;

import org.springframework.stereotype.Component;
import org.springframework.validation.Errors;
import org.springframework.validation.ValidationUtils;
import org.springframework.validation.Validator;

import com.last1mile.model.Serve;

@Component("serveValidator")
public class ServeValidator implements Validator {

    @Override
    public boolean supports(Class<?> clazz) {
        return Serve.class.isAssignableFrom(clazz);
    }

    @Override
    public void validate(Object target, Errors errors) {
        ValidationUtils.rejectIfEmptyOrWhitespace(errors, "serveTitle", "required.serveTitle","Field name is required.");
        ValidationUtils.rejectIfEmptyOrWhitespace(errors, "serveDesc", "required.serveDesc", "Field name is required.");
        ValidationUtils.rejectIfEmptyOrWhitespace(errors, "priceDesc", "required.priceDesc","Field name is required.");
        ValidationUtils.rejectIfEmptyOrWhitespace(errors, "priceAmt", "required.priceAmt", "Field name is required.");
    }

}
